function ErrorCalculatorModST
format long e

modx50=load('modx50.out');
modx100=load('modx100.out');
modx150=load('modx150.out');
modx200=load('modx200.out');
modx250=load('modx250.out');
modx300=load('modx300.out');
modx350=load('modx350.out');
modx400=load('modx400.out');
modx450=load('modx450.out');
modx500=load('modx500.out');
modx550=load('modx550.out');
modx600=load('modx600.out');

datax50=[modx50(:,1) -0.239*modx50(:,2)];
datax100=[modx100(:,1) -0.239*modx100(:,2)];
datax150=[modx150(:,1) -0.239*modx150(:,2)];
datax200=[modx200(:,1) -0.239*modx200(:,2)];
datax250=[modx250(:,1) -0.239*modx250(:,2)];
datax300=[modx300(:,1) -0.239*modx300(:,2)];
datax350=[modx350(:,1) -0.239*modx350(:,2)];
datax400=[modx400(:,1) -0.239*modx400(:,2)];
datax450=[modx450(:,1) -0.239*modx450(:,2)];
datax500=[modx500(:,1) -0.239*modx500(:,2)];
datax550=[modx550(:,1) -0.239*modx550(:,2)];
datax600=[modx600(:,1) -0.239*modx600(:,2)];

NNN=length(modx50);
fftx50=fft(datax50(:,2))/NNN;
fftx100=fft(datax100(:,2))/NNN;
fftx150=fft(datax150(:,2))/NNN;
fftx200=fft(datax200(:,2))/NNN;
fftx250=fft(datax250(:,2))/NNN;
fftx300=fft(datax300(:,2))/NNN;
fftx350=fft(datax350(:,2))/NNN;
fftx400=fft(datax400(:,2))/NNN;
fftx450=fft(datax450(:,2))/NNN;
fftx500=fft(datax500(:,2))/NNN;
fftx550=fft(datax550(:,2))/NNN;
fftx600=fft(datax600(:,2))/NNN;
fftxAll=[fftx50,fftx100,fftx150,fftx200,fftx250,fftx300,fftx350,fftx400,fftx450,fftx500,fftx550,fftx600]';

ZeroModeLoc=82;
NumModes=41;
% The following k0 value includes surface tension.
k0=0.441471407881960925;
epsilon=2*k0*abs(fftx50(ZeroModeLoc));

ExptGauges=abs(fftxAll(:,ZeroModeLoc-NumModes:ZeroModeLoc+NumModes));
[MMM,JJJ]=size(ExptGauges);

NLSSTAlldata=epsilon/k0*load('NLSSTAlldata.out');
dNLSSTAlldata=epsilon/k0*load('dNLSSTAlldata.out');
DystheSTAlldata=epsilon/k0*load('DystheSTAlldata.out');
vDystheSTAlldata=epsilon/k0*load('vDystheSTAlldata.out');
dGTSTAlldata=epsilon/k0*load('dGTSTAlldata.out');
NLSSTGauges=NLSSTAlldata(1:500:5501,:);
dNLSSTGauges=dNLSSTAlldata(1:500:5501,:);
DystheSTGauges=DystheSTAlldata(1:500:5501,:);
vDystheSTGauges=vDystheSTAlldata(1:500:5501,:);
dGTSTGauges=dGTSTAlldata(1:500:5501,:);

HannahNLSSTError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-NLSSTGauges').^2)./sum((abs(ExptGauges')).^2))
HannahdNLSSTError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-dNLSSTGauges').^2)./sum((abs(ExptGauges')).^2))
HannahDystheSTError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-DystheSTGauges').^2)./sum((abs(ExptGauges')).^2))
HannahvDystheSTError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-vDystheSTGauges').^2)./sum((abs(ExptGauges')).^2))
HannahdGTSTError=100/JJJ/(MMM-1)*sum(sum((ExptGauges'-dGTSTGauges').^2)./sum((abs(ExptGauges')).^2))

u1p=4;
u2p=8;
u3p=10;
l1m=4;
l2m=8;
l3m=10;

a0s=abs(fftxAll(:,ZeroModeLoc));
an1s=abs(fftxAll(:,ZeroModeLoc-l1m));
a1s=abs(fftxAll(:,ZeroModeLoc+u1p));
an2s=abs(fftxAll(:,ZeroModeLoc-l2m));
a2s=abs(fftxAll(:,ZeroModeLoc+u2p));
an3s=abs(fftxAll(:,ZeroModeLoc-l3m));
a3s=abs(fftxAll(:,ZeroModeLoc+u3p));

carrier=(JJJ+1)/2;
u1=carrier+u1p;
u2=carrier+u2p;
u3=carrier+u3p;
l1=carrier-l1m;
l2=carrier-l2m;
l3=carrier-l3m;

NLSSTcarrier=NLSSTAlldata(1:100:end,carrier);
dNLSSTcarrier=dNLSSTAlldata(1:100:end,carrier);
DystheSTcarrier=DystheSTAlldata(1:100:end,carrier);
vDystheSTcarrier=vDystheSTAlldata(1:100:end,carrier);
dGTSTcarrier=dGTSTAlldata(1:100:end,carrier);
NLSu1=NLSSTAlldata(1:100:end,u1);
dNLSu1=dNLSSTAlldata(1:100:end,u1);
Dystheu1=DystheSTAlldata(1:100:end,u1);
vDystheu1=vDystheSTAlldata(1:100:end,u1);
dGTSTu1=dGTSTAlldata(1:100:end,u1);
NLSu2=NLSSTAlldata(1:100:end,u2);
dNLSu2=dNLSSTAlldata(1:100:end,u2);
Dystheu2=DystheSTAlldata(1:100:end,u2);
vDystheu2=vDystheSTAlldata(1:100:end,u2);
dGTSTu2=dGTSTAlldata(1:100:end,u2);
NLSu3=NLSSTAlldata(1:100:end,u3);
dNLSu3=dNLSSTAlldata(1:100:end,u3);
Dystheu3=DystheSTAlldata(1:100:end,u3);
vDystheu3=vDystheSTAlldata(1:100:end,u3);
dGTSTu3=dGTSTAlldata(1:100:end,u3);

NLSl1=NLSSTAlldata(1:100:end,l1);
dNLSl1=dNLSSTAlldata(1:100:end,l1);
Dysthel1=DystheSTAlldata(1:100:end,l1);
vDysthel1=vDystheSTAlldata(1:100:end,l1);
dGTSTl1=dGTSTAlldata(1:100:end,l1);
NLSl2=NLSSTAlldata(1:100:end,l2);
dNLSl2=dNLSSTAlldata(1:100:end,l2);
Dysthel2=DystheSTAlldata(1:100:end,l2);
vDysthel2=vDystheSTAlldata(1:100:end,l2);
dGTSTl2=dGTSTAlldata(1:100:end,l2);
NLSl3=NLSSTAlldata(1:100:end,l3);
dNLSl3=dNLSSTAlldata(1:100:end,l3);
Dysthel3=DystheSTAlldata(1:100:end,l3);
vDysthel3=vDystheSTAlldata(1:100:end,l3);
dGTSTl3=dGTSTAlldata(1:100:end,l3);

positions=[0,50,100,150,200,250,300,350,400,450,500,550]';
x=0:1/10:5500/10;
x=x(1:100:end);

figure(6)
subplot(4,2,[1,2])
hold off
scatter(positions,a0s,'filled','k')
hold on
plot(x,NLSSTcarrier,'k')
plot(x,DystheSTcarrier,'k--')
l=legend('data','NLS','Dysthe','Location','SouthWest','Orientation','horizontal','FontSize',7);
l.NumColumns=2;
ylabel('$|a_0|$','Interpreter','Latex')
title('Expt A First Harmonic')
axis tight
subplot(4,2,3)
hold off
scatter(positions,an1s,'filled','k')
hold on
plot(x,NLSl1,'k')
plot(x,Dysthel1,'k--')
ylabel('$|a_{-4}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.04])
subplot(4,2,4)
hold off
scatter(positions,a1s,'filled','k')
hold on
plot(x,NLSu1,'k')
plot(x,Dystheu1,'k--')
ylabel('$|a_4|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.04])
subplot(4,2,5)
hold off
scatter(positions,an2s,'filled','k')
hold on
plot(x,NLSl2,'k')
plot(x,Dysthel2,'k--')
ylabel('$|a_{-8}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.02])
subplot(4,2,6)
hold off
scatter(positions,a2s,'filled','k')
hold on
plot(x,NLSu2,'k')
plot(x,Dystheu2,'k--')
ylabel('$|a_8|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.02])
subplot(4,2,7)
hold off
scatter(positions,an3s,'filled','k')
hold on
plot(x,NLSl3,'k')
plot(x,Dysthel3,'k--')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{-10}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.002])
subplot(4,2,8)
hold off
scatter(positions,a3s,'filled','k')
hold on
plot(x,NLSu3,'k')
plot(x,Dystheu3,'k--')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{10}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.002])



figure(66)
subplot(4,2,[1,2])
hold off
scatter(positions,a0s,'filled','k')
hold on
plot(x,dNLSSTcarrier,'k')
plot(x,vDystheSTcarrier,'k--')
plot(x,dGTSTcarrier,'k-.')
l=legend('data','dNLS','vDysthe','dGT','Location','NorthEast','Orientation','horizontal');
l.NumColumns=2;
ylabel('$|a_0|$','Interpreter','Latex')
title('Expt A First Harmonic')
axis tight
subplot(4,2,3)
hold off
scatter(positions,an1s,'filled','k')
hold on
plot(x,dNLSl1,'k')
plot(x,vDysthel1,'k--')
plot(x,dGTSTl1,'k-.')
ylabel('$|a_{-4}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.04])
subplot(4,2,4)
hold off
scatter(positions,a1s,'filled','k')
hold on
plot(x,dNLSu1,'k')
plot(x,vDystheu1,'k--')
plot(x,dGTSTu1,'k-.')
ylabel('$|a_4|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.04])
subplot(4,2,5)
hold off
scatter(positions,an2s,'filled','k')
hold on
plot(x,dNLSl2,'k')
plot(x,vDysthel2,'k--')
plot(x,dGTSTl2,'k-.')
ylabel('$|a_{-8}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.02])
subplot(4,2,6)
hold off
scatter(positions,a2s,'filled','k')
hold on
plot(x,dNLSu2,'k')
plot(x,vDystheu2,'k--')
plot(x,dGTSTu2,'k-.')
ylabel('$|a_8|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.02])
subplot(4,2,7)
hold off
scatter(positions,an3s,'filled','k')
hold on
plot(x,dNLSl3,'k')
plot(x,vDysthel3,'k--')
plot(x,dGTSTl3,'k-.')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{-10}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.002])
subplot(4,2,8)
hold off
scatter(positions,a3s,'filled','k')
hold on
plot(x,dNLSu3,'k')
plot(x,vDystheu3,'k--')
plot(x,dGTSTu3,'k-.')
xlabel('$x$ (cm)','Interpreter','Latex')
ylabel('$|a_{10}|$','Interpreter','Latex')
xlim([0 x(end)])
ylim([0 0.002])
